package com.sh.rbac.domain.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.sh.rbac.core.mybatis.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.util.Set;

/**
 * 用户实体类
 *
 * @author lucky
 * @since 2024-04-05 13:57
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class User extends BaseEntity {

    private Long deptId;
    private String username;
    private String nickname;
    private String password;
    private String email;
    private String phone;
    private Integer sex;
    private String avatar;
    private Integer usertype;
    private String lastLoginIp;
    @Schema(description = "状态;0-正常,1-停用")
    private Integer status;

    @Schema(description = "优先级")
    private Integer priority;

    @Schema(description = "备注")
    private String remark;


    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastLoginTime;

    @TableField(exist = false)
    private Set<String> permissions;

    @TableField(exist = false)
    private Set<Role> roles;

    @TableField(exist = false)
    private String deptName;
    @Schema(description = "用户令牌")
    @TableField(exist = false)
    private String token;
    @Schema(description = "过期时间")
    @TableField(exist = false)
    private Long expiration;
    @TableField(exist = false)
    private String loginIp;
    @TableField(exist = false)
    private String loginLocation;
    @TableField(exist = false)
    private String browser;
    @TableField(exist = false)
    private String os;

    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(exist = false)
    private LocalDateTime loginTime;
}
